<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :span="24" class="card-box">
        <el-card>
          <div slot="header"><span>CPU</span></div>
          <div class="el-table el-table--enable-row-hover el-table--medium">
            <table cellspacing="0" style="width: 100%;">
              <tbody>
                <tr>
                  <td><div class="cell">属性</div></td>
                  <td><div class="cell">值</div></td>
                </tr>
                <tr>
                  <td><div class="cell">核心数</div></td>
                  <td><div class="cell">{{ server.cpu.cpuNum }}</div></td>
                </tr>
                <tr>
                  <td><div class="cell">用户使用率</div></td>
                  <td><div class="cell">{{ server.cpu.used }}%</div></td>
                </tr>
                <tr>
                  <td><div class="cell">系统使用率</div></td>
                  <td><div class="cell">{{ server.cpu.sys }}%</div></td>
                </tr>
                <tr>
                  <td><div class="cell">当前空闲率</div></td>
                  <td><div class="cell">{{ server.cpu.free }}%</div></td>
                </tr>
              </tbody>
            </table>
          </div>
        </el-card>
      </el-col>

      <el-col :span="24" class="card-box">
        <el-card>
          <div slot="header"><span>内存</span></div>
          <div class="el-table el-table--enable-row-hover el-table--medium">
            <table cellspacing="0" style="width: 100%;">
              <tbody>
                <tr>
                  <td><div class="cell">属性</div></td>
                  <td><div class="cell">内存</div></td>
                  <td><div class="cell">JVM</div></td>
                </tr>
                <tr>
                  <td><div class="cell">总内存</div></td>
                  <td><div class="cell">{{ server.mem.total }}G</div></td>
                  <td><div class="cell">{{ server.jvm.total }}M</div></td>
                </tr>
                <tr>
                  <td><div class="cell">已用内存</div></td>
                  <td><div class="cell">{{ server.mem.used }}G</div></td>
                  <td><div class="cell">{{ server.jvm.used }}M</div></td>
                </tr>
                <tr>
                  <td><div class="cell">剩余内存</div></td>
                  <td><div class="cell">{{ server.mem.free }}G</div></td>
                  <td><div class="cell">{{ server.jvm.free }}M</div></td>
                </tr>
                <tr>
                  <td><div class="cell">使用率</div></td>
                  <td><div class="cell">{{ server.mem.usage }}%</div></td>
                  <td><div class="cell">{{ server.jvm.usage }}%</div></td>
                </tr>
              </tbody>
            </table>
          </div>
        </el-card>
      </el-col>

      <el-col :span="24" class="card-box">
        <el-card>
          <div slot="header"><span>服务器信息</span></div>
          <div class="el-table el-table--enable-row-hover el-table--medium">
            <table cellspacing="0" style="width: 100%;">
              <tbody>
                <tr>
                  <td><div class="cell">服务器名称</div></td>
                  <td><div class="cell">{{ server.sys.computerName }}</div></td>
                </tr>
                <tr>
                  <td><div class="cell">操作系统</div></td>
                  <td><div class="cell">{{ server.sys.osName }}</div></td>
                </tr>
                <tr>
                  <td><div class="cell">服务器IP</div></td>
                  <td><div class="cell">{{ server.sys.computerIp }}</div></td>
                </tr>
                <tr>
                  <td><div class="cell">系统架构</div></td>
                  <td><div class="cell">{{ server.sys.osArch }}</div></td>
                </tr>
              </tbody>
            </table>
          </div>
        </el-card>
      </el-col>

      <el-col :span="24" class="card-box">
        <el-card>
          <div slot="header"><span>Java虚拟机信息</span></div>
          <div class="el-table el-table--enable-row-hover el-table--medium">
            <table cellspacing="0" style="width: 100%;">
              <tbody>
                <tr>
                  <td><div class="cell">Java名称</div></td>
                  <td><div class="cell">{{ server.jvm.name }}</div></td>
                </tr>
                <tr>
                  <td><div class="cell">Java版本</div></td>
                  <td><div class="cell">{{ server.jvm.version }}</div></td>
                </tr>
                <tr>
                  <td><div class="cell">启动时间</div></td>
                  <td><div class="cell">{{ server.jvm.startTime }}</div></td>
                </tr>
                <tr>
                  <td><div class="cell">运行时长</div></td>
                  <td><div class="cell">{{ server.jvm.runTime }}</div></td>
                </tr>
              </tbody>
            </table>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { getServer } from "@/api/monitor/server";

export default {
  name: "Server",
  data() {
    return {
      server: {
        cpu: {},
        mem: {},
        jvm: {},
        sys: {}
      }
    };
  },
  created() {
    this.getServer();
  },
  methods: {
    /** 查询服务器信息 */
    getServer() {
      getServer().then(response => {
        this.server = response.data;
      });
    }
  }
};
</script>

<style scoped>
.card-box {
  padding-bottom: 15px;
}
</style>